package cn.com.nes.site.aspects;

import cn.com.nes.site.entity.em.project.ImportLogsTypeEnum;
import cn.com.nes.site.entity.iot.CustomerSurveyExcel;
import cn.com.nes.site.entity.vo.project.ImportGovernmentalCustomerArchiveVO;
import cn.com.nes.site.service.logs.ImportLogDetailsService;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


/**
 * 系统切面日志
 *
 * @author lizb
 * @date 2019/8/12 11:18
 */
@Aspect
@Component
@Slf4j
public class WebLogAspect {

    @Resource
    ImportLogDetailsService importLogDetailsService;

    @Pointcut("@annotation(cn.com.nes.common.annotation.Logs)")
    public void pointOne() {
    }

    @Around("pointOne()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        Object result = "";
        try {
            result = proceedingJoinPoint.proceed();
        } catch (Exception e) {
            e.printStackTrace();
            e.getMessage();
            Object[] args = proceedingJoinPoint.getArgs();
            if (args.length >= 2) {
                //将参数所在的数组转换成json
                ImportGovernmentalCustomerArchiveVO vo = (ImportGovernmentalCustomerArchiveVO) args[0];
                CustomerSurveyExcel item = (CustomerSurveyExcel) args[1];
//                DistinctByPropertyUtils.insertDetailsData(importLogDetailsService, item, vo, e.getMessage(), "02");
                importLogDetailsService.AspectInsertDetailsData(item, vo, e.getMessage(), ImportLogsTypeEnum.PROJECT_IMPORT.getKey());
            }
        }
        return result;
    }

}
